import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-10-25
 * Time: 19:36
 */
//重定向
    @WebServlet("/redirect")
public class RedirectServlet extends HelloServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        //第一种写法
//        resp.setStatus(302);
//        resp.setHeader("Location","http://www.baidu.com");
        //第二种
        resp.sendRedirect("http://www.sogou.com");
    }
}
